package cn.hnedu.dms.biz;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sun.mail.iap.Response;

import cn.hnedu.dms.BeanUtils;
import cn.hnedu.dms.entity.UserBase;
import cn.hnedu.util.StringUtils;

public  class BaseBiz {
	
	private BeanUtils bean;

	public BeanUtils getBean() {
		if(bean==null){
			bean=new BeanUtils();
		}
		return bean;
	}
	
	public boolean checkUser(HttpServletRequest request)
	{
		UserBase user=this.bean.getUserFromSession(request);
		if(user==null)
			return false;
		else {
			return true;
		}
	}
	
	public static void alertMessage(String message,String url,HttpServletResponse response){
		PrintWriter out =null;
		try {
			response.setCharacterEncoding("UTF-8");
			out=response.getWriter();
			StringBuffer buffer=new StringBuffer();
			buffer.append("<script>");
			if(!StringUtils.isNull(message))
			{
				buffer.append("alert('"+message+"');");
			}
			if(!StringUtils.isNull(url)){
				buffer.append("location='"+url+"';");
			}
			buffer.append("</script>");
			out.print(buffer);			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			out.close();
		}
	}
}
